package com.ardf.service.impl;

import com.ardf.common.EntityConstants;
import com.ardf.entity.Algorithm;
import com.ardf.entity.dto.AlgorithmMenuDto;
import com.ardf.mapper.AlgorithmMapper;
import com.ardf.service.IAlgorithmService;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author ShiYunHao
 * @since 2025-01-06
 */
@Service
public class AlgorithmServiceImpl extends ServiceImpl<AlgorithmMapper, Algorithm> implements IAlgorithmService {

    private final AlgorithmMapper algorithmMapper;
    public AlgorithmServiceImpl(AlgorithmMapper algorithmMapper){
        this.algorithmMapper=algorithmMapper;
    }
    @Override
    public List<AlgorithmMenuDto> getAlgorithmMenu(Long ruleId) {
        List<Algorithm> algorithms = algorithmMapper.selectList(new LambdaQueryWrapper<Algorithm>()
                .eq(Algorithm::getRuleId, ruleId));
        return algorithms.stream().map(algorithm -> {
            AlgorithmMenuDto algorithmMenuDto = new AlgorithmMenuDto();
            algorithmMenuDto.setAlgorithmId(algorithm.getId());
            algorithmMenuDto.setAlgorithmDescription(
                    EntityConstants.ALGORITHM_TYPE_DESCRIPTION_MAP.get(algorithm.getType()));
            if (EntityConstants.ALGORITHM_STATUS_AGREED_FINAL.equals(algorithm.getStatus()) ||
                    EntityConstants.ALGORITHM_STATUS_AGREED_NO_FINAL.equals(algorithm.getStatus())) {
                algorithmMenuDto.setAlgorithmName("(商定)" + EntityConstants.ALGORITHM_TYPE_NAME_MAP.get(algorithm.getType()));
            } else {
                algorithmMenuDto.setAlgorithmName(EntityConstants.ALGORITHM_TYPE_NAME_MAP.get(algorithm.getType()));
            }
            return algorithmMenuDto;
        }).toList();
    }
}
